package com.cm.caseManagement.controller;
import com.cm.caseManagement.annotation.Log;
import com.cm.caseManagement.core.controller.BaseController;
import com.cm.caseManagement.core.domain.AjaxResult;
import com.cm.caseManagement.core.page.TableDataInfo;
import com.cm.caseManagement.pojo.entity.CmCaseIncome;
import com.cm.caseManagement.pojo.enums.BusinessType;
import com.cm.caseManagement.service.ICmCaseIncomeService;
import com.cm.caseManagement.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 案件收支Controller
 *
 * @author ruoyi
 * @date 2025-10-05
 */
@RestController
@RequestMapping("/caseManagement/income")
public class CmCaseIncomeController extends BaseController
{
    @Autowired
    private ICmCaseIncomeService cmCaseIncomeService;

    /**
     * 查询案件收支列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:income:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmCaseIncome cmCaseIncome)
    {
        startPage();
        List<CmCaseIncome> list = cmCaseIncomeService.selectCmCaseIncomeList(cmCaseIncome);
        return getDataTable(list);
    }

    /**
     * 导出案件收支列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:income:export')")
    @Log(title = "案件收支", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmCaseIncome cmCaseIncome)
    {
        List<CmCaseIncome> list = cmCaseIncomeService.selectCmCaseIncomeList(cmCaseIncome);
        ExcelUtil<CmCaseIncome> util = new ExcelUtil<CmCaseIncome>(CmCaseIncome.class);
        util.exportExcel(response, list, "案件收支数据");
    }

    /**
     * 获取案件收支详细信息
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:income:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cmCaseIncomeService.selectCmCaseIncomeById(id));
    }

    /**
     * 新增案件收支
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:income:add')")
    @Log(title = "案件收支", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmCaseIncome cmCaseIncome)
    {
        return toAjax(cmCaseIncomeService.insertCmCaseIncome(cmCaseIncome));
    }

    /**
     * 修改案件收支
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:income:edit')")
    @Log(title = "案件收支", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmCaseIncome cmCaseIncome)
    {
        return toAjax(cmCaseIncomeService.updateCmCaseIncome(cmCaseIncome));
    }

    /**
     * 删除案件收支
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:income:remove')")
    @Log(title = "案件收支", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmCaseIncomeService.deleteCmCaseIncomeByIds(ids));
    }
}
